import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;

/**
 * class that make the output graphs
 *
 */
public class OutputGraphs {
	
	
	BufferedWriter bufferOut1;
	BufferedWriter bufferOut2;
	BufferedWriter bufferOut3;
	BufferedWriter bufferOut4;
	BufferedWriter bufferOut5;

	
	/**
	 * calculate the avg fitness
	 * @return the avgFitness of exactly population 
	 */
	
	
	public void outToFile(int max) {
		try {
			bufferOut1.write(max +"\r\n");
//			bufferOut3.write(componenetsAVG()+"\n\r");
//			bufferOut4.write(placedCorrectAVG()+"\n\r");
			bufferOut1.flush();
			bufferOut2.flush();
			bufferOut3.flush();
			bufferOut4.flush();
			
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		
	}

	/**
	 * writes the data of the question one to a file
	 * 
	 * @param data
	 * @throws IOException
	 */
	public void questionOne(QuestionData[] data) throws IOException {
		bufferOut1=new BufferedWriter(new FileWriter("out1.txt"));
		for (int i=0; i<10; i++)
		{
			System.out.println(data[i].getMax() + " "+data[i].getAvg());
			bufferOut1.write((i+1) +";"+data[i].getAvg()+";"+data[i].getMax()+"\r\n");
		}
		bufferOut1.flush();
		
	}
	/**
	 * writes the data of the question two to a file
	 * 
	 * @param data
	 * @throws IOException
	 */
	public void questionTwo(QuestionData[][] data) throws IOException {
		bufferOut2=new BufferedWriter(new FileWriter("out2.txt"));
		for (int i = 0; i < data.length; i++) {
			System.out.println("for n = avg is "+i);
			bufferOut2.write((i+1)+";");
			for (int j = 0; j < data[i].length; j++) {
				System.out.print(data[i][j].getAvg()+" ");
				bufferOut2.write(data[i][j].getAvg()+";");
				
			}
			bufferOut2.write("\r\n");
		}
		bufferOut2.flush();
		for (int i = 0; i < data.length; i++) {
			System.out.println("for n = max is "+i);
			bufferOut2.write((i+1)+";");
			for (int j = 0; j < data[i].length; j++) {
				System.out.print(data[i][j].getMax()+" ");
				bufferOut2.write(data[i][j].getMax()+";");
				
			}
			bufferOut2.write("\r\n");
		}
		bufferOut2.flush();
		
		
	}
	/**
	 * writes the data of the question three to a file
	 * 
	 * @param data
	 * @throws IOException
	 */
	public void questionThree(QuestionData[] data) throws IOException {
		bufferOut3=new BufferedWriter(new FileWriter("out3.txt"));
		for (int i=0; i<10; i++)
		{
			System.out.println(data[i].getMax() + " "+data[i].getAvg());
			bufferOut3.write((i+1) +";"+data[i].getAvg()+";"+data[i].getMax()+"\r\n");
		}
		bufferOut3.flush();
		
	}
	
	/**
	 * writes the data of the question four to a file
	 * 
	 * @param data
	 * @throws IOException
	 */
	public void questionFour(QuestionData[][] data) throws IOException {
		bufferOut4=new BufferedWriter(new FileWriter("out4.txt"));
		for (int i = 0; i < data.length; i++) {
			System.out.println("for n = avg is "+i);
			bufferOut4.write((i+1)+";");
			for (int j = 0; j < data[i].length; j++) {
				System.out.print(data[i][j].getAvg()+" ");
				bufferOut4.write(data[i][j].getAvg()+";");
				
			}
			bufferOut4.write("\r\n");
		}
		bufferOut4.flush();
		for (int i = 0; i < data.length; i++) {
			System.out.println("for n = max is "+i);
			bufferOut4.write((i+1)+";");
			for (int j = 0; j < data[i].length; j++) {
				System.out.print(data[i][j].getMax()+" ");
				bufferOut4.write(data[i][j].getMax()+";");
				
			}
			bufferOut4.write("\r\n");
		}
		bufferOut4.flush();
		
		
	}

	 
}
